package com.scc.mapper;
import com.scc.pojo.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface AdminMapper {
    //管理员登录的查询操作
    @Select("select * from admin where username=#{username} and PASSWORD=#{password}")
    Admin select(Admin admin);

    //管理员添加操作员工信息操作
    @Insert("INSERT INTO emp (name, gender, image, account, password, salary, createTime, lastOperationTime) " +
            "VALUE (#{name},#{gender},#{image},#{account},#{password},#{salary},#{createTime},#{lastOperationTime}) ")
    void addEmp(Emp emp);

    //查询员工信息
    List<Emp> page(@Param("name") String name, @Param("gender") Integer gender, @Param("account") String account, @Param("beginTime") LocalDate beginTime, @Param("endTime") LocalDate endTime);

    //删除一个员工的方法
    @Delete("delete from emp where id=#{id}")
    void delete(Integer id);

    //批量删除员工的方法
    void deleteByIds(List<Integer> ids);


    //管理员端修改密码
    @Update("update admin set PASSWORD = #{password} where username = #{username} ")
    void updatePassword(Admin admin);


    //获取单个用户的信息
    @Select("select * from emp where id = #{id}")
    Emp getEmpMessageById(Integer id);


    //修改员工信息
    void modify(@Param("id") Integer id, @Param("name") String name, @Param("gender") Integer gender, @Param("image") String image,
                @Param("account") String account, @Param("password") String password, @Param("salary") Integer salary,
                @Param("lastOperationTime") LocalDate lastOperationTime);


    //获得所有员工的信息
    @Select("select * from emp")
    List<Emp> getAllEmpMessage();


    //添加考勤信息
    @Insert("INSERT INTO attendance (name,gender,account,deductSalary,attendanceDate,attendanceName,endAttendanceTime)" +
            "value (#{name},#{gender},#{account},#{deductSalary},#{attendanceDate},#{attendanceName},#{endAttendanceTime})")
    void addAttendance(Attendance attendance);


    //查询考勤信息
    List<Attendance> getAllAttendance(@Param("name") String name, @Param("gender") Integer gender, @Param("account") String account, @Param("empAttendanceStatus") Integer empAttendanceStatus, @Param("attendanceDate") LocalDate attendanceDate);


    //根据id删除考勤表的信息
    void deleteAttendanceByIds(List<Integer> ids);


    //根据id扣除工资
    void deductSalary(List<Integer> ids, @Param("money") Integer money);


    //找到扣除工资的员工姓名，账号，要在员工表中扣除工资
    @Select("select * from attendance where id = #{id} ")
    Attendance getAttendanceById(Integer id);


    //根据员工账号对员工表的员工工资和已扣工资，进行加减操作
    void modifyEmpByAccount(@Param("account") String account,@Param("money") Integer money);


    //查询或者获取全部员工请假数据
    List<Leave> getEmpLeaveMsg(@Param("name") String name, @Param("gender") Integer gender, @Param("account") String account, @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate);

    //跟据id来操作用户审批状态
    void modifyEmpLeaveApproveStatus(@Param("ids") List<Integer> ids, @Param("approveStatus") Integer approveStatus);

    //查询或者获取全部员工离职表的信息
    List<Resign> getEmpResignMsg(@Param("name") String name, @Param("gender") Integer gender, @Param("account") String account, @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate);

    //管理员审批员工离职申请
    void modifyEmpResignApproveStatus(@Param("ids") List<Integer> ids, @Param("resignStatus") Integer resignStatus, @Param("resignDate") LocalDate resignDate);

    //团建活动数据的获取
    List<TeamBuildingActivities> getTeamBuildingActivitiesMsg(@Param("teamBuildingName") String teamBuildingName, @Param("activityStatus") Integer activityStatus, @Param("begin") LocalDateTime begin, @Param("end") LocalDateTime end);

    //新增团建活动
    @Insert("insert into teambuildingactivities (teamBuildingName,maxCapacity,startTime,endTime) value " +
            "(#{teamBuildingName},#{maxCapacity},#{startTime},#{endTime})")
    void addTeamBuildingActivities(TeamBuildingActivities teamBuildingActivities);

    //删除团建活动
    void deleteTeamBuildingActivities(List<Integer> ids);

    //根据id获取团建活动的信息
    @Select("select * from teambuildingactivities where id = #{id}")
    TeamBuildingActivities getTeamBuildingActivitiesMsgById(Integer id);

    //更具id修改团建活动的信息
    void modifyTeamBuildingActivities(@Param("id") Integer id, @Param("teamBuildingName") String teamBuildingName, @Param("maxCapacity") Integer maxCapacity, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime, @Param("activityStatus") Integer activityStatus);

    //查询单个团建活动的员工报名信息
    List<EmpTeamBuildingActivityRegistration> geEmpTeamBuildingActivitiesMsg(@Param("id") Integer id, @Param("name") String name, @Param("gender") Integer gender, @Param("account") String account, @Param("activityDuration") String activityDuration, @Param("begin") LocalDateTime begin, @Param("end") LocalDateTime end, @Param("empActivityStatus") Integer empActivityStatus);

    //修改员工报名团建活动的信息表
    @Update("update empteambuildingactivityregistration set teamBuildingName = #{teamBuildingName} where id = #{id}")
    void modifyEmpTeamBuildingActivities(Integer id, String teamBuildingName);

    //删除团建活动时，要把员工团建信息的数据根据id删除
    void deleteEmpTeamBuildingActivities(List<Integer> ids);

    //删除团建活动员工报名表的数据根据账号
    void deleteEmpTeamBuildingActivitiesByAccounts(List<String> account);

    //培训活动信息表的获取和查询
    List<TrainingActivity> getTrainingActivities(@Param("trainingName") String trainingName, @Param("activityStatus") Integer activityStatus, @Param("startTime") LocalDate startTime, @Param("endTime") LocalDate endTime);

    //培训活动信息表的删除
    void deleteTrainingActivityByIds(List<Integer> ids);

    //根据id获取培训活动的信息
    @Select("select * from trainingactivity where id = #{id}")
    TrainingActivity getTrainingActivityMsgById(Integer id);

    ///添加培训活动
    @Insert("insert into trainingactivity (trainingName, maxCapacity, startTime, endTime,trainingPlan) value" +
            " (#{trainingName},#{maxCapacity},#{startTime},#{endTime},#{trainingPlan})")
    void addTrainingActivity(TrainingActivity trainingActivity);

    //修改培训活动
    @Update("update trainingactivity set trainingName=#{trainingName},maxCapacity=#{maxCapacity},startTime=#{startTime},endTime=#{endTime},activityStatus=#{activityStatus} where id = #{id}")
    void modifyTrainingActivity(TrainingActivity trainingActivity);

    //员工培训活动报名表删除
    void deleteEmpTrainingActivityByIds(List<Integer> ids);

    //查看某个培训活动的报名信息或者查找
    List<EmpTrainingActivity> getEmpTrainingActivity(@Param("id") Integer id, @Param("name") String name, @Param("gender") Integer gender, @Param("account") String account, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime, @Param("activityStatus") Integer activityStatus, @Param("activityDuration") String activityDuration, @Param("activityScore") Integer activityScore);

    //管理员根据员工账号删除员工培训报名表员工的信息
    void deleteEmpTrainingActivityByAccounts(@Param("accounts") List<String> accounts);

    //要对培训活动员工报名表进行修改分数
    void modifyEmpTrainingActivityScore(@Param("activityScore") Integer activityScore, @Param("account") String account);

    //要对员工总表进行加分
    void modifyEmpTrainingScore(@Param("activityScore") Integer activityScore, @Param("account") String account);

    //获取员工培训分数操作
    @Select("select activityScore from emptrainingactivity where account = #{account} and id = #{id}")
    Integer getEmpTrainingActivityScoreByAccount(String account, Integer id);

    //查询员工请假表获取审批通过的员工账号
    List<String> getEmpAccountByIds(@Param("ids") List<Integer> ids);

    //根据员工账号修改员工考勤表的考勤状态->修改为请假(管理员请假审批通过)
    void modifyEmpAttendanceStatus(@Param("accounts") List<String> accounts);

    //管理员结算员工工资,对员工工资表进行添加
    @Insert("insert into empsalary (id, account, salaryDate, deductSalary, salary) " +
            "value(#{id},#{account},#{salaryDate},#{deductSalary},#{salary})")
    void insertEmpSalary(EmpSalary empSalary);

    //管理员结算完成之后要对员工下一个月的工资清零
    @Update("update emp set salary = #{oldSalary},deductSalary = 0 where id = #{id} and account = #{account}")
    void initializationSalary(int id, String account, int oldSalary);

    ///批量获取员工信息根据id
    List<Emp> getEmpMsgByIds(@Param("ids") List<Integer> ids);

    @Select("select * from admin where username = #{account}")
    void selectAdminMsg(String account);

    //获取员工在线信息表的信息
    List<EmpOnLine> selectEmpOnlineMsg(@Param("name") String name, @Param("account") String account, @Param("start") LocalDate start, @Param("end") LocalDate end);

    //管理员根据id删除员工在线信息表的信息
    void deleteEmpOnlineMsgByIds(@Param("ids") List<Integer> ids);
}
